#include "TcpServer.hpp"   // 通信管理，负责建立和断开通信 -> 会话层
#include "NetCal.hpp"      // 针对特定的计算协议 -> 应用层
#include "IOService.hpp"   // 负责数据个数转换 -> 表示层
#include <memory>

// 自己建立端口号
int main(int argc, char* argv[]) {
    if (argc != 2) {
        LOG(ERROR, "please input: ./server port\n");
        return 1;
    }
    uint16_t port = std::stoi(argv[1]);
    
    NetCal calculator;
    calculate_t cal = std::bind(&NetCal::Calculator, &calculator, std::placeholders::_1);
    IOService io_forword;
    tcp_task_t task = std::bind(
        &IOService::IOForword, 
        &io_forword, cal, 
        std::placeholders::_1, 
        std::placeholders::_2
    );
    
    std::unique_ptr<TcpServer> tsvr = std::make_unique<TcpServer>(task, port);
    tsvr->Init();
    tsvr->Start();

    return 0;
}